<?php

require_once("../lib/defines.types.php");
header("Content-Type: text/javascript");


echo "var typeLookup = new Object();\n\n";
foreach ($typeLookup as $id=>$name) {
	echo "var ".$name." = ".$id.";\n";
	echo "typeLookup[".$id."] = '".$name."';\n";
	echo "\n";
}

echo "var typeDisplayNameLookup = new Object();\n\n";
foreach ($displayNameLookup as $id=>$name) {
	echo "typeDisplayNameLookup[".$id."] = '".$name."';\n";
	echo "\n";
}

?>

function fillType(typeId) {

	switch (typeId) {
<?php
foreach ($typeLookup as $id=>$name) {
	echo "\t\tcase ".$name.":\n";
	$values = fillType($id);
	if ($values) {
		echo "\t\t\tvar toReturn = new Object();\n";
		for ($i=0; $i<sizeof($values); $i++) {
			echo "\t\t\ttoReturn['".$values[$i]->getId()."'] = '".$values[$i]->getLabel()."';\n";
		}
		echo "\t\t\treturn toReturn;\n";
	}
	echo "\t\t\tbreak;\n";
}
?>
	}

	return new Object();

}

function getTypeIdFromDisplayName(name) {
	for (id in typeDisplayNameLookup) {
		if (typeDisplayNameLookup[id] == name) {
			return parseInt(id);
		}
	}
	return null;
}

function getTypeDisplayNameFromLabel(lbl) {

	var typeId = false;

	for (id in typeLookup) {
		if (typeLookup[id] == lbl) {
			typeId = id;
			break;
		}
	}

	if (typeId) {
		return typeDisplayNameLookup[typeId];
	}

	return null;
}



function getMacros(typeId) {

	var toReturn = new Array();

<?php
foreach ($macroLookup as $typeIds=>$values) {

	echo "\tif (typeId & ".$typeIds.") {\n";
	if (is_array($values)) {
		for ($i=0; $i<sizeof($values); $i++) {
			$macroName 	 = $values[$i][0];
			$macroIsMultiple = $values[$i][2];
			$macroIsMultipleStr = "false";
			if ($macroIsMultiple) {
				$macroIsMultipleStr = "true";
			}

			echo "\t\ttoReturn.push(new Array('".$macroName."', ".$macroIsMultipleStr."));\n";
		}
	}
	echo "\t}\n";
}
?>

	return toReturn;

}